140 LOCATE 25,1:PRINT "Press any key to continue . . .";
145 ANS$=INPUT$(1):CLS
150 PRINT TAB(27) "PC-FILE III to WORDPERFECT"
155 PRINT TAB(26) "Data File Conversion Program"
160 PRINT:PRINT
165 PRINT " This program allows you to convert any PC-FILE data file into the required"
170 PRINT "format for use by WordPerfect's MERGE program."
175 PRINT:PRINT " Before beginning, you should be sure that both the xxxxx.DTA and the"
180 PRINT "xxxxx.HDR files are in any drive, and that there is sufficient disk space"
185 PRINT "to receive the resulting xxxxx.WP file.
190 PRINT:PRINT " Also, you must have booted BASIC (or compiled the program) using "
195 PRINT "the /S:xxxx option, allowing for total bytes per record."
200 PRINT:PRINT " You may wish to sort and selectively `clone' the PC-FILE data before using"
205 PRINT "this conversion program, although if you have WordPerfect's SORT program, you"
210 PRINT "can sort and select after the conversion."
215 PRINT:PRINT " If you have a large database or intend to convert often, it would be wise"
220 PRINT "to compile this program first."
225 LOCATE 25,1:PRINT "Press any key to continue . . .";
230 ANS$=INPUT$(1)
1000 ' Get the filename and drive specifications
1010 KEY OFF:CLS
1020 DIM HDR$(200),FLD(2000),FLD$(2000)
1030 ON ERROR GOTO 10000
1040 PRINT "What is the name of the file to be converted (No extensions)";
1050 INPUT FIL$
1060 Y$=".":X=INSTR(FIL$,Y$):IF X>0 THEN FIL$=LEFT$(FIL$,X-1)
1070 IF LEN(FIL$)>8 THEN FIL$="":PRINT "Maximum 8 characters in filename";: GOTO 1050
1080 INPUT "Which drive has the data (No colon)";INDRV$
1090 IF INDRV$="" THEN GOTO 1080
1100 INPUT "Which drive for the output file (No colon)";OUTDRV$
1110 IF OUTDRV$="" THEN GOTO 1100
1120 INFILE1$=LEFT$(INDRV$,1)+":"+FIL$+".HDR"
1130 INFILE2$=LEFT$(INDRV$,1)+":"+FIL$+".DTA"
1140 OUTFILE$=LEFT$(OUTDRV$,1)+":"+FIL$+".WP
1150 ' Get field and record length information
1160 OPEN "I",1,INFILE1$
1170 WHILE NOT EOF(1)
1180 CTR=CTR+1
1190 LINE INPUT #1,HDR$(CTR)
1200 INPUT #1,FLD(CTR)
1210 IF TOTFLD(PASS)+FLD(CTR)>256 THEN PASS=PASS+1
1220 TOTFLD(PASS)=TOTFLD(PASS)+FLD(CTR)
1230 WEND
1240 CLOSE
1250 CLS:PRINT "For your information, the following fields and lengths"
1260 PRINT "apply to each record in the ";CHR$(34);FIL$;CHR$(34);" database."
1270 PRINT
1280 FOR LOOP = 1 TO CTR
1290 IF LOOP>20 THEN LOCATE (LOOP-17),40
1300 PRINT LOOP;" ";HDR$(LOOP);" =";FLD(LOOP)
1310 NEXT
1320 LOCATE 25,1:PRINT "Press any key to continue . . .";
1330 ANS$=INPUT$(1):CLS
1340 FOR TOTAL=0 TO PASS:TOTFLDS=TOTFLDS+TOTFLD(TOTAL):NEXT
1350 IF TOTFLDS>128 THEN PRINT "The total length of each record is";TOTFLDS;" Make sure you have booted":PRINT "BASIC using the /S: option.":LOCATE 25,1:PRINT "Press any key to continue . . .";:ANS$=INPUT$(1):CLS
2000 ' Read the Data from PC-FILE
2010 OPEN "R",1,INFILE2$,TOTFLDS+1
2020 FIELD 1,TOTFLD(0) AS INFO$(0),TOTFLD(1) AS INFO$(1),TOTFLD(2) AS INFO$(2), TOTFLD(3) AS INFO$(3)
2030 ' Prepare File for Output (Data is Appended)
2040 OPEN "A",2,OUTFILE$
2050 RCDS = INT(LOF(1)/TOTFLDS)
2060 FOR LOOP = 1 TO RCDS
2070 PLC=1:PASS=0
2080 GET #1,LOOP
2090 FOR SPLIT= 1 TO CTR
2100 IF PLC+FLD(SPLIT)>256 THEN PLC=1:PASS=PASS+1
2110 FLD$(SPLIT)=MID$(INFO$(PASS),PLC,FLD(SPLIT))
2120 PLC=PLC+FLD(SPLIT)
2130 NEXT
2140 IF LEFT$(INFO$(0),1)="\" THEN GOTO 2170
2150 GOSUB 2180
2160 NEXT
2170 CLS:PRINT "Conversion of the ";CHR$(34);FIL$;CHR$(34);" database to ";CHR$(34);FIL$;".WP";CHR$(34);" is now completed."
2171 PRINT
2172 PRINT "NOTE: The ";FIL$;".WP file is a DOS file and has miscellaneous"
2173 PRINT " characters at the end. Retrieve this file using WordPerfect's"
2174 PRINT " ALT-F1 (Extended Features) as a DOS (ASCII) file and then"
2175 PRINT " re-save it as you normally do. The file will then be ready"
2176 PRINT " to use with WordPerfect's merge program."
2178 LOCATE 23,1:END
2180 ' Print Record to Output File
2190 FOR PRINTOUT=1 TO CTR
2200 FOR STRIP=LEN(FLD$(PRINTOUT)) TO 1 STEP -1
2210 IF MID$(FLD$(PRINTOUT),STRIP,1)<>" " THEN 2230 ELSE FLD$(PRINTOUT)=LEFT$(FLD$(PRINTOUT),(LEN(FLD$(PRINTOUT))-1))
2260 PRINT #2,CHR$(5)+CHR$(10); 'End of record marker for WordPerfect
2270 RETURN
10000 ' Error Trapping Routines
10010 PRINT:PRINT:PRINT
10020 IF ERR=50 THEN PRINT "A field overflow has occurred. You must reboot BASIC using the":PRINT "/s: option to allocate bytes for record lengths in excess":PRINT "of 128 bytes.":PRINT "Press any key to return to DOS.":ANS$=INPUT$(1):SYSTEM
10030 IF ERR=53 AND ERL=1160 THEN PRINT "The file ";INFILE1$;" was not found.":PRINT "Do you wish to revise the (D)rive, (F)ilename, or mount the proper disk and (R)esume? (D,F,R)":ANS$=INPUT$(1):ELSE GOTO 10060
10040 IF ANS$="D" OR ANS$="d" THEN CLS:RESUME 1080:ELSE IF ANS$="F" OR ANS$="f" THEN CLS:RESUME 1040:ELSE IF ANS$="R" OR ANS$="r" THEN RESUME:ELSE GOTO 10030
10050 IF ERR=53 AND ERL=2010 THEN PRINT "The file ";INFILE2$;" was not found.":PRINT "Do you wish to revise the (D)rive, (F)ilename, or mount the proper disk and (R)esume? (D,F,R)":ANS$=INPUT$(1):GOTO 10040
10060 IF ERR=61 THEN PRINT "Insufficient disk space. Please correct and then . . .":PRINT " Press any key to resume.":ANS$=INPUT$(1):RESUME
10070 IF ERR=70 THEN PRINT "Disk is write-protected. Please correct and then . . .":PRINT " Press any key to resume.":ANS$=INPUT$(1):RESUME
10080 IF ERR=71 THEN PRINT "Disk is not ready (door open?). Please correct and then . . .":PRINT " Press any key to resume.":ANS$=INPUT$(1):RESUME
10090 IF ERR=64 THEN CLS:PRINT "You have used an improper filename.":PRINT:RESUME 1040
10100 PRINT "Error #";ERR;" has occurred in line";ERL:PRINT " Please refer to the BASIC manual and correct before running the program":PRINT:PRINT"Press any key to return to DOS.":ANS$=INPUT$(1):SYSTEM